package ar.uba.fi.tp2Unit.framework;

import java.util.HashMap;
import java.util.Map;


/**
 * It represents a test fixture. A collection of 
 * pairs <key, value> to be accessed and modified
 * by the {@link Test}s who share it.
 * 
 * @author grupo12
 * @see {@link Test}, {@linkplain TestCase}, {@link TestSuite}
 *
 */
public class TestFixture {
	
	private Map<String, Object> fixture;
	
	public TestFixture(){
		this.fixture = new HashMap<String, Object>();
	}
	
	public void add(String name, Object value){
		fixture.put(name, value);
	}
	
	public Object get(String name){
		if(existsName(name)){
			return fixture.get(name);
		}
		throw new NonExistentFixtureValueException(name);
	}
	
	public void remove(String name){
		if(existsName(name)){
			fixture.remove(name);
		} else {
			throw new NonExistentFixtureValueException(name);
		}
	}
	
	public void clear(){
		fixture.clear();
	}

	private boolean existsName(String name) {
		return fixture.containsKey(name);
	}
}
